package com.woniuxy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.system.entity.DataRecord;
import com.woniuxy.system.entity.PerformanceUser;
import com.woniuxy.system.mapper.DataRecordMapper;
import com.woniuxy.system.mapper.PerformanceUserMapper;
import com.woniuxy.system.service.PerformanceUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 用户表	 服务实现类
 * </p>
 *
 * @author woniuxy
 * @since 2022-06-01
 */
@Service
public class PerformanceUserServiceImpl extends ServiceImpl<PerformanceUserMapper, PerformanceUser> implements PerformanceUserService {

    @Autowired
    DataRecordMapper dataRecordMapper;
    @Autowired
    PerformanceUserMapper performanceUserMapper;

    @Override
    public Page<PerformanceUser> getAllPerformanceUser(IPage<PerformanceUser> page, Wrapper<PerformanceUser> wrapper) {
        return performanceUserMapper.getAllPerformanceUser(page,wrapper);
    }

    @Override
    public boolean addPerformanceUser(PerformanceUser performanceUser, String userid) {
        DataRecord dataRecord = new DataRecord();
        dataRecord.setCreateTime(new Date());
        dataRecord.setInfo("新增员工");
        dataRecord.setUserId(Long.valueOf(userid));
        int insert = dataRecordMapper.insert(dataRecord);
        System.out.println("datarecordeId="+dataRecord.getId());
        performanceUser.setRecordId(dataRecord.getId());
        int insert1 = performanceUserMapper.insert(performanceUser);
        if(insert==1&&insert1==1){
            return  true;
        }
        return false;
    }
}
